package com.fire.control.system.module.company.dao;

import java.util.List;

import org.apache.ibatis.annotations.Select;

import com.fire.control.system.dto.CompanyResultDTO;
import com.fire.control.system.dto.SelectCompanyDTO;
import com.fire.control.system.entity.Company;
import com.fire.control.system.entity.User;
import com.fire.control.system.support.protocol.management.ManagementRequestProtocol;

public interface CompanyMapper{
	
	@Select("select * from t_company where status=1")
	public List<Company> getAllCompanys();
	
	/**
	 * @author: xiechengguang 
	 * @Title: getCompanys   
	 * @Description: 获取当前企业或者其下属企业  
	 */
	@Select("select id,company_name from t_company c where c.id = #{companyId} or c.parent_id = #{companyId}")
	public List<SelectCompanyDTO> getCompanys(String companyId);
	
	/**
	 * @author: xiechengguang 
	 * @Title: getCompanyDto   
	 * @Description: 获取当前企业dto
	 */
	@Select("select id,company_name from t_company c where c.id = #{companyId}")
	public SelectCompanyDTO getCompanyDto(String companyId);
	
	/**
	 * @author: xiechengguang 
	 * @Title: getCompanyByUserId   
	 * @Description: 通过用户id获取所在企业  
	 */
	@Select("SELECT c.* from t_company c JOIN t_users u ON c.id = u.company_id WHERE u.id = #{userId}")
	public Company getCompanyByUserId(String userId);
	
	/**
	 * @author: xiechengguang 
	 * @Title: getById   
	 * @Description: 通过企业id获取企业  
	 */
	@Select("SELECT c.* from t_company c WHERE c.id = #{id}")
	public Company getById(String id);
	
	
	/**
	 * 根据条件查询单位列表
	 */
	public List<CompanyResultDTO> getCompanyByCondition(ManagementRequestProtocol requestProtocol);
	
	/**
	 * 获得选中单位信息
	 */
	public List<CompanyResultDTO> getCheckManagementList(ManagementRequestProtocol requestProtocol);
	
	/**
	 * @author liuxincheng
	 * @Title: getParentCompany
	 * @Description: TODO(根据用户Id获得上层单位)
	 * @param @param requestProtocol
	 * @param @return    设定文件
	 * @return List<Company>    返回类型
	 * @throws null
	 */
	public List<Company> getParentCompany(String userId);
	
	/**
	 * @author liuxincheng
	 * @Title: getUserListByCompanyId
	 * @Description: TODO(根据企业Id获取用户列表)
	 * @param @param companyId
	 * @param @return    设定文件
	 * @return List<User>    返回类型
	 * @throws
	 */
	@Select("select u.* from t_users u where u.company_id =#{companyId}")
	public List<User> getUserListByCompanyId(String companyId);
}
